package com.innovation.chengzhangriji.ui.widget;

import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.innovation.chengzhangriji.R;
import com.makeramen.roundedimageview.RoundedImageView;
import com.nostra13.universalimageloader.core.ImageLoader;

public class ThumbnailViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

    public interface ThumbnailViewListener {

        void onClickThumbnail(ThumbnailViewHolder holder);

        void onClickDelete(ThumbnailViewHolder holder);

    }

    /*缩略图*/
    private RoundedImageView mThumbnailView;

    /*删除按钮*/
    private CuteImageView mDeleteButton;

    private ThumbnailViewListener mListener;

    public ThumbnailViewHolder(View itemView) {
        super(itemView);
        mThumbnailView = (RoundedImageView) itemView.findViewById(R.id.image_thumbnail);
        mDeleteButton = (CuteImageView) itemView.findViewById(R.id.button_delete);
        mThumbnailView.setOnClickListener(this);
        mDeleteButton.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (mListener == null) {
            return;
        }
        switch (v.getId()) {
            case R.id.image_thumbnail:
                mListener.onClickThumbnail(this);
                break;
            case R.id.button_delete:
                mListener.onClickDelete(this);
                break;
        }
    }

    public void setThumbnailViewListener(ThumbnailViewListener thumbnailViewListener) {
        mListener = thumbnailViewListener;
    }

    @Override
    public String toString() {
        return super.toString();
    }

    /**
     * 设置缩略图
     * @param url 图片路径
     */
    public void setThumbnail(String url) {
        ImageLoader.getInstance().displayImage("file://" + url, mThumbnailView);
    }
}
